Import('sys', 'env', 'hasCollada', 'stubs', 'winstubs')

# Create an environment with Xerces and OpenGL
mainEnv = env.Clone()
if 'XERCESINCLUDE' in mainEnv: # mainEnv.has_key('XERCESINCLUDE'):
        mainEnv.Prepend(CPPPATH=mainEnv['XERCESINCLUDE'])
if 'XERCESLIBDIR' in mainEnv: # mainEnv.has_key('XERCESLIBDIR'):
        mainEnv.Prepend(LIBPATH=mainEnv['XERCESLIBDIR'])
if 'XERCESLIB' in mainEnv: # mainEnv.has_key('XERCESLIB'):
        mainEnv.Prepend(LIBS=mainEnv['XERCESLIB'])
if 'GLLIB' in mainEnv: # mainEnv.has_key('GLLIB'):
        mainEnv.Prepend(LIBS=mainEnv['GLLIB'])
if 'GLLIBDIR' in mainEnv: # mainEnv.has_key('GLLIBDIR'):
        mainEnv.Prepend(LIBPATH=mainEnv['GLLIBDIR'])
if 'GLFLAGS' in mainEnv: # mainEnv.has_key('GLFLAGS'):
        mainEnv.Prepend(CXXFLAGS=mainEnv['GLFLAGS'])
if 'GLINCLUDE' in mainEnv: # mainEnv.has_key('GLINCLUDE'):
        mainEnv.Prepend(CPPPATH=mainEnv['GLINCLUDE'])

if sys.platform == 'darwin':
        # On OSX, we need this stub to access OpenGL from the command line
        mainEnv_osx = mainEnv.Clone()
        mainEnv_osx.ConfigureForObjectiveCPP()
        stubs += [mainEnv_osx.StaticObject('darwin_stub.mm')]
        mainEnv.Append(LINKFLAGS=['-Xlinker', '-rpath', '-Xlinker', '@executable_path/../Frameworks'])

mainEnv.Program('mtsutil', stubs + winstubs + ['mtsutil.cpp'])

# Build the command-line+GUI interface
mainEnv.Program('mtssrv',  winstubs + ['mtssrv.cpp'])
mainEnv.Program('mitsuba', winstubs + ['mitsuba.cpp'])

Return('mainEnv')
